/**
 * 公历年取农历节日
 * @param y int|string 公历年
 * @param k string|null 节日  见:代码NAME的KEY null:取全年
 * @return object  json:{'Y-M-D':chs}  异常或无节日:空json
 * 		'Y-M-D':公历年月日  腊八节公历一年可能存在2天或0天
 */
$.dateMoonFest = function(y, k=null){
	const NAME = {
		lb:'腊八节',cx:'除夕',  cj:'春节',  yx:'元宵节',lt:'龙抬头',
		ss:'上巳节',qm:'清明节',dw:'端午节',qx:'七夕节',zy:'中元节',
		zq:'中秋节',cy:'重阳节',hy:'寒衣节',xy:'下元节',
	};
	const FMT = function(rtn, key, ymd, day){
		if(!ymd) return;  let [y, m, d] = ymd;
		if(day){
			let o=new Date(new Date(ymd.join('/')+' 00:00:00')*1+day*864E5);
			y=o.getFullYear();  m=o.getMonth()+1;  d=o.getDate();
		}
		rtn[y+'-'+(m>9?m:'0'+m)+'-'+(d>9?d:'0'+d)] = NAME[key];
	};
	const FEST = function(y, k, rtn){
		if(k==='lb'){ // 腊八节
			k=$.dateMoon(y-1,12,8,true); if(k&&k[0]===y) FMT(rtn,'lb',k);
			k=$.dateMoon(y,12,8,true);  if(k&&k[0]===y) FMT(rtn,'lb',k);
		}
		else if(k==='cx') FMT(rtn,k,$.dateMoon(y,1,1,true),-1);//除夕
		else if(k==='cj') FMT(rtn,k,$.dateMoon(y,1,1,true));  //春节
		else if(k==='yx') FMT(rtn,k,$.dateMoon(y,1,15,true)); //元宵节
		else if(k==='lt') FMT(rtn,k,$.dateMoon(y,2,2,true));  //龙抬头
		else if(k==='ss') FMT(rtn,k,$.dateMoon(y,3,3,true));  //上巳节
		else if(k==='qm'){ // 清明节,春分后15天
			let x = $.dateMoonTerm(y, 5);
			if(x) FMT(rtn, k, x.slice(1), 15);
		}
		else if(k==='dw') FMT(rtn,k,$.dateMoon(y,5,5,true));  //端午节
		else if(k==='qx') FMT(rtn,k,$.dateMoon(y,7,7,true));  //七夕节
		else if(k==='zy') FMT(rtn,k,$.dateMoon(y,7,15,true)); //中元节
		else if(k==='zq') FMT(rtn,k,$.dateMoon(y,8,15,true)); //中秋节
		else if(k==='cy') FMT(rtn,k,$.dateMoon(y,9,9,true));  //重阳节
		else if(k==='hy') FMT(rtn,k,$.dateMoon(y,10,1,true)); //寒衣节
		else if(k==='xy') FMT(rtn,k,$.dateMoon(y,10,15,true));//下元节
	};
	$.dateMoonFest = function(y, k=null){
		let rtn={};  if(!(y*=1) || y<1900 || y>2100) return rtn;
		if(k!==null){ FEST(y,k,rtn); return rtn; }
		Object.keys(NAME).forEach(k=>FEST(y,k,rtn)); return rtn;
	};
	return $.dateMoonFest(y, k);
};
